﻿using Autofac;
using Microsoft.AspNetCore.Mvc;
using PlutoStudio.Dependency;
using System;
using System.Collections.Generic;
using System.Text;

namespace PlutoStudio.AspNetCore
{
    public class AspNetCoreConventionalRegistrar : IConventionalDependencyRegistrar
    {
        public void RegisterAssembly(IConventionalRegistrationContext context)
        {
            context.Builder.RegisterAssemblyTypes(context.Assembly)
                .Where(t => t.IsAssignableTo<ViewComponent>() && !t.IsGenericTypeDefinition)
                .AsSelf()
                .AsImplementedInterfaces()
                .As<ViewComponent>()
                .AsLifeStyle(LifetimeScopeStyle.Transient)
                .PropertiesAutowired(new PropertySelector());
        }
    }
}
